'''
https://www.nowcoder.com/practice/fd55637d3f24484e96dad9e992d3f62e
'''
import sys

n, V = map(int, input().split())
vs, ws = [0] * n, [0] * n
i = 0
for line in sys.stdin:
    vs[i], ws[i] = map(int, line.split())
    i += 1

A = [-1] * (V + 1)
A[0] = 0
for i in range(n - 1, -1, -1):
    B = [-1] * (V + 1)
    for rest in range(V + 1):
        r1 = A[rest]
        r2 = (A[rest - vs[i]]) if vs[i] <= rest else -1
        if r2 != -1:
            r2 += ws[i]
        B[rest] = max(r1, r2)
    A = B

print(A[V])
res2 = 0 if A[V] == -1 else A[V]
print(res2)
